import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import p001 from './p001';
export default async function a004(fd: IFeidaoAiBrowserComponent, address: string) {
	// 修改页面样式
	const add = fd.data.node.querySelector<HTMLElement>('[data-id="updata"]');
	set_node_cls(add, 'display-n', false);
	if (address === undefined) {
		return;
	} else {
		// 获取项目数据
		const project = fd.data.node.querySelector<HTMLSelectElement>('[data-id="project"]');
		const project_no = project.value;
		// 获取资产名称
		const assetsname = fd.data.node.querySelector<HTMLInputElement>('[data-id="assetsname"]').value;
		// 获取资产类型
		const asset_classification = fd.data.node.querySelector<HTMLSelectElement>('[data-id="asset_classification"]');
		const asset_classification_no = asset_classification.value;
		const project_asset_no = get(fd, 'project_asset_no');
		// 获取资产等级
		const asset_grade = fd.data.node.querySelector<HTMLSelectElement>('[data-id="asset_grade"]').value;
		// 获取品牌
		const brand_no = fd.data.node.querySelector<HTMLInputElement>('[data-id="brand_no"]').value;
		// 获取部门名称
		const equip_depart_name = get(fd, 'equip_depart_name');
		// 获取是否客户资产
		const customer_assets = fd.data.node.querySelector<HTMLSelectElement>('[data-id="customer_assets"]').value;
		// 获取单价
		const unitprice = fd.data.node.querySelector<HTMLInputElement>('[data-id="unitprice"]').value;
		// 获取资产维修时长
		const maintenance_time = fd.data.node.querySelector<HTMLInputElement>('[data-id="maintenance_time"]').value;
		// 获取是否超时提醒
		const timeout_alert = fd.data.node.querySelector<HTMLSelectElement>('[data-id="timeout_alert"]').value;
		// 获取维护说明
		const remark = fd.data.node.querySelector<HTMLTextAreaElement>('[data-id="remark"]').value;
		// 获取超时提请时长
		const timeout_reminder_time = fd.data.node.querySelector<HTMLInputElement>('[data-id="timeout_reminder_time"]').value;
		const dt1 = [{
			asset_classification_no,
			asset_grade,
			assetsname,
			brand_no,
			customer_assets,
			equip_depart_name,
			maintenance_time,
			place: address,
			timeout_alert,
			timeout_reminder_time,
			unitprice,
			project_no,
			remark
		}];
		// 根据项目资产编号获取项目资产数据
		const res = await nodejs<{ dt1: { equip_depart_name: string }; dt2: Array<{}>; dt3: Array<{}> }>('project-assets/zj-000004/s001', {
			project_asset_no
		});
		const data = Object.assign({ dt1 }, { dt2: res.dt2 }, { dt3: res.dt3 });
		render(fd, data, p001, 'p001', 'inner');
	}
}
